# Replication code for Claudia J. Kim and Taylor C. Boas, "Activist Disconnect: Social Movements, Public Opinion, and U.S. Military Bases in East Asia," Armed Forces and Society.

# Analysis conducted in R 3.6.0 on MacOS 10.13.6

# NOTE: This file conducts all analysis for the main text and appendix except for Appendix Figures 9-10 (in screener_analysis.R) and Appendix Table 1 and Appendix Figures 3-6 (in representativeness.R). It includes, at the end of the file, results conveyed textually. 

# Set working directory as appropriate
# setwd('~/Dropbox/us_bases_experiment/replication/')

# Clean desktop and load packages. Please make sure all necessary packages are installed.

rm(list=ls(all=T))

library(Hmisc)

# Load cleaned dataset

load('basedata_cleaned.RData')

# Function to demean covariates

demean<-function(x) x-mean(x,na.rm=T)

# Rename/recode variables

basedata$Age<-basedata$Q4
basedata$Male<-basedata$Q33==1
basedata$Education<-basedata$Q34
basedata$Satisfaction<-basedata$Q35
basedata$Duty_vote<-basedata$Q6
basedata$Efficacy<-basedata$Q7
basedata$Petition<-basedata$Q8
basedata$Boycott<-basedata$Q9
basedata$Demonstration<-basedata$Q10
basedata$Donate<-basedata$Q11
basedata$Ideology<-basedata$Q13
basedata$Extremism<-abs(basedata$Q13-5.5)
basedata$Distance_org<-abs(basedata$Q13-ifelse(basedata$Country=='Korea',basedata$Q16,basedata$Q20))
basedata$Local_news<-basedata$Q22
basedata$Nat_news<-basedata$Q23
basedata$Conflict<-basedata$Q28
basedata$Intervention<-basedata$Q29
basedata$Attitude<-basedata$Q30
basedata$Behavior<-basedata$Q37
basedata$TreatA<-basedata$Q30_cond==1
basedata$TreatB<-basedata$Q30_cond==2
basedata$TreatC<-basedata$Q30_cond==3
basedata$TreatD<-basedata$Q30_cond==4
basedata$TreatE<-basedata$Q30_cond==5
basedata$TreatF<-basedata$Q30_cond==6
basedata$TreatG<-basedata$Q30_cond==7
basedata$TreatH<-basedata$Q30_cond==8
basedata$Daegu<-basedata$Q5=='Daegu'
basedata$Gyeonggi<-basedata$Q5=='Gyeonggi'
basedata$Kanagawa<-basedata$Q5=='Kanagawa'
basedata$Okinawa<-basedata$Q5=='Okinawa'
basedata$Region<-basedata$Q5
basedata$Screener<-basedata$Q25==14
basedata$Mil_presence<- basedata$Q32

# Fixed effects and covariates used as controls in regressions

regions<-c('demean(Daegu)', 'demean(Gyeonggi)', 'demean(Kanagawa)', 'demean(Okinawa)')

covars<-c('demean(Age)', 'demean(Male)', 'demean(Education)', 'demean(Satisfaction)', 'demean(Duty_vote)', 'demean(Efficacy)', 'demean(Petition)', 'demean(Boycott)', 'demean(Demonstration)', 'demean(Donate)', 'demean(Ideology)', 'demean(Extremism)', 'demean(Distance_org)', 'demean(Local_news)', 'demean(Nat_news)', 'demean(Conflict)', 'demean(Intervention)')

############
# Testing H1
############

# No Covariates

h1_pure_att<-with(basedata[(basedata$TreatC | basedata$TreatA),], lm(as.formula(paste0('Attitude ~ TreatC + ', paste(regions, '* TreatC', collapse = ' + ')))))
h1_reg_att<-with(basedata[(basedata$TreatC | basedata$TreatB),], lm(as.formula(paste0('Attitude ~ TreatC + ', paste(regions, '* TreatC', collapse = ' + ')))))
h1_pure_beh<-with(basedata[(basedata$TreatC | basedata$TreatA),], lm(as.formula(paste0('Behavior ~ TreatC + ', paste(regions, '* TreatC', collapse = ' + ')))))
h1_reg_beh<-with(basedata[(basedata$TreatC | basedata$TreatB),], lm(as.formula(paste0('Behavior ~ TreatC + ', paste(regions, '* TreatC', collapse = ' + ')))))

h1_pure_att_korea<-with(basedata[(basedata$TreatC | basedata$TreatA) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatC + ', paste(regions, '* TreatC', collapse = ' + ')))))
h1_reg_att_korea<-with(basedata[(basedata$TreatC | basedata$TreatB) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatC + ', paste(regions, '* TreatC', collapse = ' + ')))))
h1_pure_att_japan<-with(basedata[(basedata$TreatC | basedata$TreatA) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatC + ', paste(regions, '* TreatC', collapse = ' + ')))))
h1_reg_att_japan<-with(basedata[(basedata$TreatC | basedata$TreatB) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatC + ', paste(regions, '* TreatC', collapse = ' + ')))))

# Covariates

h1_pure_att_covar<-with(basedata[(basedata$TreatC | basedata$TreatA),], lm(as.formula(paste0('Attitude ~ TreatC + ', paste(covars, '* TreatC', collapse = ' + '), '+', paste(regions, '* TreatC', collapse = ' + ')))))
h1_reg_att_covar<-with(basedata[(basedata$TreatC | basedata$TreatB),], lm(as.formula(paste0('Attitude ~ TreatC + ', paste(covars, '* TreatC', collapse = ' + '), '+', paste(regions, '* TreatC', collapse = ' + ')))))
h1_pure_beh_covar<-with(basedata[(basedata$TreatC | basedata$TreatA),], lm(as.formula(paste0('Behavior ~ TreatC + ', paste(covars, '* TreatC', collapse = ' + '), '+', paste(regions, '* TreatC', collapse = ' + ')))))
h1_reg_beh_covar<-with(basedata[(basedata$TreatC | basedata$TreatB),], lm(as.formula(paste0('Behavior ~ TreatC + ', paste(covars, '* TreatC', collapse = ' + '), '+', paste(regions, '* TreatC', collapse = ' + ')))))

h1_pure_att_korea_covar<-with(basedata[(basedata$TreatC | basedata$TreatA) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatC + ', paste(covars, '* TreatC', collapse = ' + '), '+', paste(regions, '* TreatC', collapse = ' + ')))))
h1_reg_att_korea_covar<-with(basedata[(basedata$TreatC | basedata$TreatB) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatC + ', paste(covars, '* TreatC', collapse = ' + '), '+', paste(regions, '* TreatC', collapse = ' + ')))))
h1_pure_att_japan_covar<-with(basedata[(basedata$TreatC | basedata$TreatA) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatC + ', paste(covars, '* TreatC', collapse = ' + '), '+', paste(regions, '* TreatC', collapse = ' + ')))))
h1_reg_att_japan_covar<-with(basedata[(basedata$TreatC | basedata$TreatB) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatC + ', paste(covars, '* TreatC', collapse = ' + '), '+', paste(regions, '* TreatC', collapse = ' + ')))))

# Gather coefficients and confidence intervals

ci_level<-.9

ate_h1_pure_att<-sapply(list(h1_pure_att, h1_pure_att_korea,  h1_pure_att_japan), function(x) coef(x)[2])
ate_h1_pure_att_covar<-sapply(list(h1_pure_att_covar, h1_pure_att_korea_covar,  h1_pure_att_japan_covar), function(x) coef(x)[2])
ate_h1_reg_att<-sapply(list(h1_reg_att, h1_reg_att_korea,  h1_reg_att_japan), function(x) coef(x)[2])
ate_h1_reg_att_covar<-sapply(list(h1_reg_att_covar, h1_reg_att_korea_covar,  h1_reg_att_japan_covar), function(x) coef(x)[2])

ci_h1_pure_att<-sapply(list(h1_pure_att, h1_pure_att_korea,  h1_pure_att_japan), function(x) confint(x, level=ci_level)[2,])
ci_h1_pure_att_covar<-sapply(list(h1_pure_att_covar, h1_pure_att_korea_covar,  h1_pure_att_japan_covar), function(x) confint(x, level=ci_level)[2,])
ci_h1_reg_att<-sapply(list(h1_reg_att, h1_reg_att_korea,  h1_reg_att_japan), function(x) confint(x, level=ci_level)[2,])
ci_h1_reg_att_covar<-sapply(list(h1_reg_att_covar, h1_reg_att_korea_covar,  h1_reg_att_japan_covar), function(x) confint(x, level=ci_level)[2,])

# Appendix Figure 11

lwd<-2
adjust<-0.2
nvars<-length(ate_h1_pure_att)
cex<-1
cex.point<-1.5

pdf(file='h1_att.pdf',width=6.5,height=4.5)
par(mar=c(3,3,1,1)+.01)
plot(ate_h1_pure_att_covar, nvars:1+0.5*adjust, type='p',axes=F,frame.plot=T,xlab='',ylab='', pch=19,xlim=c(-.5,.5), ylim=c(1-1.5*adjust,nvars+1.5*adjust),main='',sub='',cex=cex.point)
Axis(side=1,at=seq(-.5, .5, 0.125),labels= seq(-.5, .5, 0.125),cex.axis=cex)
Axis(side=2,at=c((nvars+1):0),labels=c('','All','Korea','Japan',''),las=3,cex.axis=cex, tick=F)
abline(v=0,lwd=1,lty=2)
segments(ci_h1_pure_att_covar[1,],nvars:1+0.5*adjust, ci_h1_pure_att_covar[2,],nvars:1+0.5*adjust,lwd=lwd)
segments(ci_h1_pure_att[1,],nvars:1+1.5*adjust, ci_h1_pure_att[2,],nvars:1+1.5*adjust,lwd=lwd)
segments(ci_h1_reg_att[1,],nvars:1-0.5*adjust, ci_h1_reg_att[2,],nvars:1-0.5*adjust,lwd=lwd)
segments(ci_h1_reg_att_covar[1,],nvars:1-1.5*adjust, ci_h1_reg_att_covar[2,],nvars:1-1.5*adjust,lwd=lwd)
points(ate_h1_pure_att, nvars:1+1.5*adjust, pch=21, bg='white', cex=cex.point)
points(ate_h1_reg_att, nvars:1-0.5*adjust, pch=24, bg='white', cex=cex.point)
points(ate_h1_reg_att_covar, nvars:1-1.5*adjust, pch=17, cex=cex.point)
legend('topleft',pch=c(21,19,24,17),legend=c('Pure / No','Pure / Yes','Regular / No','Regular / Yes'), title='Control / Covariates:', inset=0.04)
dev.off()

############
# Testing H2
############

# No Covariates

h2_pure_att_neg<-with(basedata[(basedata$TreatD | basedata$TreatA) & basedata$Region!='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(regions, '* TreatD', collapse = ' + ')))))
h2_reg_att_neg<-with(basedata[(basedata$TreatD | basedata$TreatB) & basedata$Region!='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(regions, '* TreatD', collapse = ' + ')))))
h2_pure_beh_neg<-with(basedata[(basedata$TreatD | basedata$TreatA) & basedata$Region!='Daegu',], lm(as.formula(paste0('Behavior ~ TreatD + ', paste(regions, '* TreatD', collapse = ' + ')))))
h2_reg_beh_neg<-with(basedata[(basedata$TreatD | basedata$TreatB) & basedata$Region!='Daegu',], lm(as.formula(paste0('Behavior ~ TreatD + ', paste(regions, '* TreatD', collapse = ' + ')))))

h2_pure_att_pos<-with(basedata[(basedata$TreatD | basedata$TreatA) & basedata$Region=='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(regions, '* TreatD', collapse = ' + ')))))
h2_reg_att_pos<-with(basedata[(basedata$TreatD | basedata$TreatB) & basedata$Region=='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(regions, '* TreatD', collapse = ' + ')))))
h2_pure_beh_pos<-with(basedata[(basedata$TreatD | basedata$TreatA) & basedata$Region=='Daegu',], lm(as.formula(paste0('Behavior ~ TreatD + ', paste(regions, '* TreatD', collapse = ' + ')))))
h2_reg_beh_pos<-with(basedata[(basedata$TreatD | basedata$TreatB) & basedata$Region=='Daegu',], lm(as.formula(paste0('Behavior ~ TreatD + ', paste(regions, '* TreatD', collapse = ' + ')))))

h2_pure_att_neg_korea<-with(basedata[(basedata$TreatD | basedata$TreatA) & basedata$Country=='Korea' & basedata$Region!='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(regions, '* TreatD', collapse = ' + ')))))
h2_reg_att_neg_korea<-with(basedata[(basedata$TreatD | basedata$TreatB) & basedata$Country=='Korea' & basedata$Region!='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(regions, '* TreatD', collapse = ' + ')))))
h2_pure_att_neg_japan<-with(basedata[(basedata$TreatD | basedata$TreatA) & basedata$Country=='Japan' & basedata$Region!='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(regions, '* TreatD', collapse = ' + ')))))
h2_reg_att_neg_japan<-with(basedata[(basedata$TreatD | basedata$TreatB) & basedata$Country=='Japan' & basedata$Region!='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(regions, '* TreatD', collapse = ' + ')))))

# Covariates

h2_pure_att_neg_covar<-with(basedata[(basedata$TreatD | basedata$TreatA) & basedata$Region!='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(covars, '* TreatD', collapse = ' + '), '+', paste(regions, '* TreatD', collapse = ' + ')))))
h2_reg_att_neg_covar<-with(basedata[(basedata$TreatD | basedata$TreatB) & basedata$Region!='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(covars, '* TreatD', collapse = ' + '), '+', paste(regions, '* TreatD', collapse = ' + ')))))
h2_pure_beh_neg_covar<-with(basedata[(basedata$TreatD | basedata$TreatA) & basedata$Region!='Daegu',], lm(as.formula(paste0('Behavior ~ TreatD + ', paste(covars, '* TreatD', collapse = ' + '), '+', paste(regions, '* TreatD', collapse = ' + ')))))
h2_reg_beh_neg_covar<-with(basedata[(basedata$TreatD | basedata$TreatB) & basedata$Region!='Daegu',], lm(as.formula(paste0('Behavior ~ TreatD + ', paste(covars, '* TreatD', collapse = ' + '), '+', paste(regions, '* TreatD', collapse = ' + ')))))

h2_pure_att_pos_covar<-with(basedata[(basedata$TreatD | basedata$TreatA) & basedata$Region=='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(covars, '* TreatD', collapse = ' + '), '+', paste(regions, '* TreatD', collapse = ' + ')))))
h2_reg_att_pos_covar<-with(basedata[(basedata$TreatD | basedata$TreatB) & basedata$Region=='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(covars, '* TreatD', collapse = ' + '), '+', paste(regions, '* TreatD', collapse = ' + ')))))
h2_pure_beh_pos_covar<-with(basedata[(basedata$TreatD | basedata$TreatA) & basedata$Region=='Daegu',], lm(as.formula(paste0('Behavior ~ TreatD + ', paste(covars, '* TreatD', collapse = ' + '), '+', paste(regions, '* TreatD', collapse = ' + ')))))
h2_reg_beh_pos_covar<-with(basedata[(basedata$TreatD | basedata$TreatB) & basedata$Region=='Daegu',], lm(as.formula(paste0('Behavior ~ TreatD + ', paste(covars, '* TreatD', collapse = ' + '), '+', paste(regions, '* TreatD', collapse = ' + ')))))

h2_pure_att_neg_korea_covar<-with(basedata[(basedata$TreatD | basedata$TreatA) & basedata$Country=='Korea' & basedata$Region!='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(covars, '* TreatD', collapse = ' + '), '+', paste(regions, '* TreatD', collapse = ' + ')))))
h2_reg_att_neg_korea_covar<-with(basedata[(basedata$TreatD | basedata$TreatB) & basedata$Country=='Korea' & basedata$Region!='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(covars, '* TreatD', collapse = ' + '), '+', paste(regions, '* TreatD', collapse = ' + ')))))
h2_pure_att_neg_japan_covar<-with(basedata[(basedata$TreatD | basedata$TreatA) & basedata$Country=='Japan' & basedata$Region!='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(covars, '* TreatD', collapse = ' + '), '+', paste(regions, '* TreatD', collapse = ' + ')))))
h2_reg_att_neg_japan_covar<-with(basedata[(basedata$TreatD | basedata$TreatB) & basedata$Country=='Japan' & basedata$Region!='Daegu',], lm(as.formula(paste0('Attitude ~ TreatD + ', paste(covars, '* TreatD', collapse = ' + '), '+', paste(regions, '* TreatD', collapse = ' + ')))))

# Gather coefficients and confidence intervals

ci_level<-.9

ate_h2a_pure_att<-sapply(list(h2_pure_att_neg,  h2_pure_att_neg_korea, h2_pure_att_neg_japan), function(x) coef(x)[2])
ate_h2a_pure_att_covar<-sapply(list(h2_pure_att_neg_covar,  h2_pure_att_neg_korea_covar, h2_pure_att_neg_japan_covar), function(x) coef(x)[2])
ate_h2a_reg_att<-sapply(list(h2_reg_att_neg,  h2_reg_att_neg_korea, h2_reg_att_neg_japan), function(x) coef(x)[2])
ate_h2a_reg_att_covar<-sapply(list(h2_reg_att_neg_covar,  h2_reg_att_neg_korea_covar, h2_reg_att_neg_japan_covar), function(x) coef(x)[2])

ci_h2a_pure_att<-sapply(list(h2_pure_att_neg,  h2_pure_att_neg_korea, h2_pure_att_neg_japan), function(x) confint(x, level=ci_level)[2,])
ci_h2a_pure_att_covar<-sapply(list(h2_pure_att_neg_covar,  h2_pure_att_neg_korea_covar, h2_pure_att_neg_japan_covar), function(x) confint(x, level=ci_level)[2,])
ci_h2a_reg_att<-sapply(list(h2_reg_att_neg,  h2_reg_att_neg_korea, h2_reg_att_neg_japan), function(x) confint(x, level=ci_level)[2,])
ci_h2a_reg_att_covar<-sapply(list(h2_reg_att_neg_covar,  h2_reg_att_neg_korea_covar, h2_reg_att_neg_japan_covar), function(x) confint(x, level=ci_level)[2,])

# Appendix Figure 12

lwd<-2
adjust<-0.2
nvars<-length(ate_h2a_pure_att)
cex<-1
cex.point<-1.5

pdf(file='h2a_att.pdf',width=6.5,height=4.5)
par(mar=c(3,3,1,1)+.01)
plot(ate_h2a_pure_att_covar, nvars:1+0.5*adjust, type='p',axes=F,frame.plot=T,xlab='',ylab='', pch=19,xlim=c(-.75,.75), ylim=c(1-1.5*adjust,nvars+1.5*adjust),main='',sub='',cex=cex.point)
Axis(side=1,at=seq(-.75, .75, 0.125),labels= seq(-.75, .75, 0.125),cex.axis=cex)
Axis(side=2,at=c((nvars+1):0),labels=c('','All','Korea','Japan',''),las=3,cex.axis=cex, tick=F)
abline(v=0,lwd=1,lty=2)
segments(ci_h2a_pure_att_covar[1,],nvars:1+0.5*adjust, ci_h2a_pure_att_covar[2,],nvars:1+0.5*adjust,lwd=lwd)
segments(ci_h2a_pure_att[1,],nvars:1+1.5*adjust, ci_h2a_pure_att[2,],nvars:1+1.5*adjust,lwd=lwd)
segments(ci_h2a_reg_att[1,],nvars:1-0.5*adjust, ci_h2a_reg_att[2,],nvars:1-0.5*adjust,lwd=lwd)
segments(ci_h2a_reg_att_covar[1,],nvars:1-1.5*adjust, ci_h2a_reg_att_covar[2,],nvars:1-1.5*adjust,lwd=lwd)
points(ate_h2a_pure_att, nvars:1+1.5*adjust, pch=21, bg='white', cex=cex.point)
points(ate_h2a_reg_att, nvars:1-0.5*adjust, pch=24, bg='white', cex=cex.point)
points(ate_h2a_reg_att_covar, nvars:1-1.5*adjust, pch=17, cex=cex.point)
legend('topleft',pch=c(21,19,24,17),legend=c('Pure / No','Pure / Yes','Regular / No','Regular / Yes'), title='Control / Covariates:', inset=0.04)
dev.off()

########################
# Testing H3a--pragmatic
########################

# No Covariates

h3a_prag_pure_att<-with(basedata[(basedata$TreatE | basedata$TreatA),], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(regions, '* TreatE', collapse = ' + ')))))
h3a_prag_reg_att<-with(basedata[(basedata$TreatE | basedata$TreatB),], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(regions, '* TreatE', collapse = ' + ')))))
h3a_prag_pure_beh<-with(basedata[(basedata$TreatE | basedata$TreatA),], lm(as.formula(paste0('Behavior ~ TreatE + ', paste(regions, '* TreatE', collapse = ' + ')))))
h3a_prag_reg_beh<-with(basedata[(basedata$TreatE | basedata$TreatB),], lm(as.formula(paste0('Behavior ~ TreatE + ', paste(regions, '* TreatE', collapse = ' + ')))))

h3a_prag_pure_att_korea<-with(basedata[(basedata$TreatE | basedata$TreatA) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(regions, '* TreatE', collapse = ' + ')))))
h3a_prag_reg_att_korea<-with(basedata[(basedata$TreatE | basedata$TreatB) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(regions, '* TreatE', collapse = ' + ')))))
h3a_prag_pure_att_japan<-with(basedata[(basedata$TreatE | basedata$TreatA) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(regions, '* TreatE', collapse = ' + ')))))
h3a_prag_reg_att_japan<-with(basedata[(basedata$TreatE | basedata$TreatB) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(regions, '* TreatE', collapse = ' + ')))))

# Covariates

h3a_prag_pure_att_covar<-with(basedata[(basedata$TreatE | basedata$TreatA),], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(covars, '* TreatE', collapse = ' + '), '+', paste(regions, '* TreatE', collapse = ' + ')))))
h3a_prag_reg_att_covar<-with(basedata[(basedata$TreatE | basedata$TreatB),], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(covars, '* TreatE', collapse = ' + '), '+', paste(regions, '* TreatE', collapse = ' + ')))))
h3a_prag_pure_beh_covar<-with(basedata[(basedata$TreatE | basedata$TreatA),], lm(as.formula(paste0('Behavior ~ TreatE + ', paste(covars, '* TreatE', collapse = ' + '), '+', paste(regions, '* TreatE', collapse = ' + ')))))
h3a_prag_reg_beh_covar<-with(basedata[(basedata$TreatE | basedata$TreatB),], lm(as.formula(paste0('Behavior ~ TreatE + ', paste(covars, '* TreatE', collapse = ' + '), '+', paste(regions, '* TreatE', collapse = ' + ')))))

h3a_prag_pure_att_korea_covar<-with(basedata[(basedata$TreatE | basedata$TreatA) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(covars, '* TreatE', collapse = ' + '), '+', paste(regions, '* TreatE', collapse = ' + ')))))
h3a_prag_reg_att_korea_covar<-with(basedata[(basedata$TreatE | basedata$TreatB) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(covars, '* TreatE', collapse = ' + '), '+', paste(regions, '* TreatE', collapse = ' + ')))))
h3a_prag_pure_att_japan_covar<-with(basedata[(basedata$TreatE | basedata$TreatA) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(covars, '* TreatE', collapse = ' + '), '+', paste(regions, '* TreatE', collapse = ' + ')))))
h3a_prag_reg_att_japan_covar<-with(basedata[(basedata$TreatE | basedata$TreatB) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(covars, '* TreatE', collapse = ' + '), '+', paste(regions, '* TreatE', collapse = ' + ')))))

# Gather coefficients and confidence intervals

ci_level<-.9

ate_h3a_prag_pure_att<-sapply(list(h3a_prag_pure_att, h3a_prag_pure_att_korea,  h3a_prag_pure_att_japan), function(x) coef(x)[2])
ate_h3a_prag_pure_att_covar<-sapply(list(h3a_prag_pure_att_covar, h3a_prag_pure_att_korea_covar,  h3a_prag_pure_att_japan_covar), function(x) coef(x)[2])
ate_h3a_prag_reg_att<-sapply(list(h3a_prag_reg_att, h3a_prag_reg_att_korea,  h3a_prag_reg_att_japan), function(x) coef(x)[2])
ate_h3a_prag_reg_att_covar<-sapply(list(h3a_prag_reg_att_covar, h3a_prag_reg_att_korea_covar,  h3a_prag_reg_att_japan_covar), function(x) coef(x)[2])

ci_h3a_prag_pure_att<-sapply(list(h3a_prag_pure_att, h3a_prag_pure_att_korea,  h3a_prag_pure_att_japan), function(x) confint(x, level=ci_level)[2,])
ci_h3a_prag_pure_att_covar<-sapply(list(h3a_prag_pure_att_covar, h3a_prag_pure_att_korea_covar,  h3a_prag_pure_att_japan_covar), function(x) confint(x, level=ci_level)[2,])
ci_h3a_prag_reg_att<-sapply(list(h3a_prag_reg_att, h3a_prag_reg_att_korea,  h3a_prag_reg_att_japan), function(x) confint(x, level=ci_level)[2,])
ci_h3a_prag_reg_att_covar<-sapply(list(h3a_prag_reg_att_covar, h3a_prag_reg_att_korea_covar,  h3a_prag_reg_att_japan_covar), function(x) confint(x, level=ci_level)[2,])

# Appendix Figure 13

lwd<-2
adjust<-0.2
nvars<-length(ate_h3a_prag_pure_att)
cex<-1
cex.point<-1.5

pdf(file='h3a_prag_att.pdf',width=6.5,height=4.5)
par(mar=c(3,3,1,1)+.01)
plot(ate_h3a_prag_pure_att_covar, nvars:1+0.5*adjust, type='p',axes=F,frame.plot=T,xlab='',ylab='', pch=19,xlim=c(-.5,.5), ylim=c(1-1.5*adjust,nvars+1.5*adjust),main='',sub='',cex=cex.point)
Axis(side=1,at=seq(-.5, .5, 0.125),labels= seq(-.5, .5, 0.125),cex.axis=cex)
Axis(side=2,at=c((nvars+1):0),labels=c('','All','Korea','Japan',''),las=3,cex.axis=cex, tick=F)
abline(v=0,lwd=1,lty=2)
segments(ci_h3a_prag_pure_att_covar[1,],nvars:1+0.5*adjust, ci_h3a_prag_pure_att_covar[2,],nvars:1+0.5*adjust,lwd=lwd)
segments(ci_h3a_prag_pure_att[1,],nvars:1+1.5*adjust, ci_h3a_prag_pure_att[2,],nvars:1+1.5*adjust,lwd=lwd)
segments(ci_h3a_prag_reg_att[1,],nvars:1-0.5*adjust, ci_h3a_prag_reg_att[2,],nvars:1-0.5*adjust,lwd=lwd)
segments(ci_h3a_prag_reg_att_covar[1,],nvars:1-1.5*adjust, ci_h3a_prag_reg_att_covar[2,],nvars:1-1.5*adjust,lwd=lwd)
points(ate_h3a_prag_pure_att, nvars:1+1.5*adjust, pch=21, bg='white', cex=cex.point)
points(ate_h3a_prag_reg_att, nvars:1-0.5*adjust, pch=24, bg='white', cex=cex.point)
points(ate_h3a_prag_reg_att_covar, nvars:1-1.5*adjust, pch=17, cex=cex.point)
legend('topleft',pch=c(21,19,24,17),legend=c('Pure / No','Pure / Yes','Regular / No','Regular / Yes'), title='Control / Covariates:', inset=0.04)
dev.off()

##########################
# Testing H3a--ideological
##########################

# No Covariates

h3a_ideol_pure_att<-with(basedata[(basedata$TreatF | basedata$TreatA),], lm(as.formula(paste0('Attitude ~ TreatF + ', paste(regions, '* TreatF', collapse = ' + ')))))
h3a_ideol_reg_att<-with(basedata[(basedata$TreatF | basedata$TreatB),], lm(as.formula(paste0('Attitude ~ TreatF + ', paste(regions, '* TreatF', collapse = ' + ')))))
h3a_ideol_pure_beh<-with(basedata[(basedata$TreatF | basedata$TreatA),], lm(as.formula(paste0('Behavior ~ TreatF + ', paste(regions, '* TreatF', collapse = ' + ')))))
h3a_ideol_reg_beh<-with(basedata[(basedata$TreatF | basedata$TreatB),], lm(as.formula(paste0('Behavior ~ TreatF + ', paste(regions, '* TreatF', collapse = ' + ')))))

h3a_ideol_pure_att_korea<-with(basedata[(basedata$TreatF | basedata$TreatA) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatF + ', paste(regions, '* TreatF', collapse = ' + ')))))
h3a_ideol_reg_att_korea<-with(basedata[(basedata$TreatF | basedata$TreatB) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatF + ', paste(regions, '* TreatF', collapse = ' + ')))))
h3a_ideol_pure_att_japan<-with(basedata[(basedata$TreatF | basedata$TreatA) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatF + ', paste(regions, '* TreatF', collapse = ' + ')))))
h3a_ideol_reg_att_japan<-with(basedata[(basedata$TreatF | basedata$TreatB) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatF + ', paste(regions, '* TreatF', collapse = ' + ')))))

# Covariates

h3a_ideol_pure_att_covar<-with(basedata[(basedata$TreatF | basedata$TreatA),], lm(as.formula(paste0('Attitude ~ TreatF + ', paste(covars, '* TreatF', collapse = ' + '), '+', paste(regions, '* TreatF', collapse = ' + ')))))
h3a_ideol_reg_att_covar<-with(basedata[(basedata$TreatF | basedata$TreatB),], lm(as.formula(paste0('Attitude ~ TreatF + ', paste(covars, '* TreatF', collapse = ' + '), '+', paste(regions, '* TreatF', collapse = ' + ')))))
h3a_ideol_pure_beh_covar<-with(basedata[(basedata$TreatF | basedata$TreatA),], lm(as.formula(paste0('Behavior ~ TreatF + ', paste(covars, '* TreatF', collapse = ' + '), '+', paste(regions, '* TreatF', collapse = ' + ')))))
h3a_ideol_reg_beh_covar<-with(basedata[(basedata$TreatF | basedata$TreatB),], lm(as.formula(paste0('Behavior ~ TreatF + ', paste(covars, '* TreatF', collapse = ' + '), '+', paste(regions, '* TreatF', collapse = ' + ')))))

h3a_ideol_pure_att_korea_covar<-with(basedata[(basedata$TreatF | basedata$TreatA) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatF + ', paste(covars, '* TreatF', collapse = ' + '), '+', paste(regions, '* TreatF', collapse = ' + ')))))
h3a_ideol_reg_att_korea_covar<-with(basedata[(basedata$TreatF | basedata$TreatB) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatF + ', paste(covars, '* TreatF', collapse = ' + '), '+', paste(regions, '* TreatF', collapse = ' + ')))))
h3a_ideol_pure_att_japan_covar<-with(basedata[(basedata$TreatF | basedata$TreatA) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatF + ', paste(covars, '* TreatF', collapse = ' + '), '+', paste(regions, '* TreatF', collapse = ' + ')))))
h3a_ideol_reg_att_japan_covar<-with(basedata[(basedata$TreatF | basedata$TreatB) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatF + ', paste(covars, '* TreatF', collapse = ' + '), '+', paste(regions, '* TreatF', collapse = ' + ')))))

# Gather coefficients and confidence intervals

ci_level<-.9

ate_h3a_ideol_pure_att<-sapply(list(h3a_ideol_pure_att, h3a_ideol_pure_att_korea,  h3a_ideol_pure_att_japan), function(x) coef(x)[2])
ate_h3a_ideol_pure_att_covar<-sapply(list(h3a_ideol_pure_att_covar, h3a_ideol_pure_att_korea_covar,  h3a_ideol_pure_att_japan_covar), function(x) coef(x)[2])
ate_h3a_ideol_reg_att<-sapply(list(h3a_ideol_reg_att, h3a_ideol_reg_att_korea,  h3a_ideol_reg_att_japan), function(x) coef(x)[2])
ate_h3a_ideol_reg_att_covar<-sapply(list(h3a_ideol_reg_att_covar, h3a_ideol_reg_att_korea_covar,  h3a_ideol_reg_att_japan_covar), function(x) coef(x)[2])

ci_h3a_ideol_pure_att<-sapply(list(h3a_ideol_pure_att, h3a_ideol_pure_att_korea,  h3a_ideol_pure_att_japan), function(x) confint(x, level=ci_level)[2,])
ci_h3a_ideol_pure_att_covar<-sapply(list(h3a_ideol_pure_att_covar, h3a_ideol_pure_att_korea_covar,  h3a_ideol_pure_att_japan_covar), function(x) confint(x, level=ci_level)[2,])
ci_h3a_ideol_reg_att<-sapply(list(h3a_ideol_reg_att, h3a_ideol_reg_att_korea,  h3a_ideol_reg_att_japan), function(x) confint(x, level=ci_level)[2,])
ci_h3a_ideol_reg_att_covar<-sapply(list(h3a_ideol_reg_att_covar, h3a_ideol_reg_att_korea_covar,  h3a_ideol_reg_att_japan_covar), function(x) confint(x, level=ci_level)[2,])

# Appendix Figure 14

lwd<-2
adjust<-0.2
nvars<-length(ate_h3a_ideol_pure_att)
cex<-1
cex.point<-1.5

pdf(file='h3a_ideol_att.pdf',width=6.5,height=4.5)
par(mar=c(3,3,1,1)+.01)
plot(ate_h3a_ideol_pure_att_covar, nvars:1+0.5*adjust, type='p',axes=F,frame.plot=T,xlab='',ylab='', pch=19,xlim=c(-.5,.5), ylim=c(1-1.5*adjust,nvars+1.5*adjust),main='',sub='',cex=cex.point)
Axis(side=1,at=seq(-.5, .5, 0.125),labels= seq(-.5, .5, 0.125),cex.axis=cex)
Axis(side=2,at=c((nvars+1):0),labels=c('','All','Korea','Japan',''),las=3,cex.axis=cex, tick=F)
abline(v=0,lwd=1,lty=2)
segments(ci_h3a_ideol_pure_att_covar[1,],nvars:1+0.5*adjust, ci_h3a_ideol_pure_att_covar[2,],nvars:1+0.5*adjust,lwd=lwd)
segments(ci_h3a_ideol_pure_att[1,],nvars:1+1.5*adjust, ci_h3a_ideol_pure_att[2,],nvars:1+1.5*adjust,lwd=lwd)
segments(ci_h3a_ideol_reg_att[1,],nvars:1-0.5*adjust, ci_h3a_ideol_reg_att[2,],nvars:1-0.5*adjust,lwd=lwd)
segments(ci_h3a_ideol_reg_att_covar[1,],nvars:1-1.5*adjust, ci_h3a_ideol_reg_att_covar[2,],nvars:1-1.5*adjust,lwd=lwd)
points(ate_h3a_ideol_pure_att, nvars:1+1.5*adjust, pch=21, bg='white', cex=cex.point)
points(ate_h3a_ideol_reg_att, nvars:1-0.5*adjust, pch=24, bg='white', cex=cex.point)
points(ate_h3a_ideol_reg_att_covar, nvars:1-1.5*adjust, pch=17, cex=cex.point)
legend('topright',pch=c(21,19,24,17),legend=c('Pure / No','Pure / Yes','Regular / No','Regular / Yes'), title='Control / Covariates:', inset=0.04)
dev.off()

############################
# Testing H3a--nationalistic
############################

# No Covariates

h3a_nat_pure_att<-with(basedata[(basedata$TreatG | basedata$TreatA),], lm(as.formula(paste0('Attitude ~ TreatG + ', paste(regions, '* TreatG', collapse = ' + ')))))
h3a_nat_reg_att<-with(basedata[(basedata$TreatG | basedata$TreatB),], lm(as.formula(paste0('Attitude ~ TreatG + ', paste(regions, '* TreatG', collapse = ' + ')))))
h3a_nat_pure_beh<-with(basedata[(basedata$TreatG | basedata$TreatA),], lm(as.formula(paste0('Behavior ~ TreatG + ', paste(regions, '* TreatG', collapse = ' + ')))))
h3a_nat_reg_beh<-with(basedata[(basedata$TreatG | basedata$TreatB),], lm(as.formula(paste0('Behavior ~ TreatG + ', paste(regions, '* TreatG', collapse = ' + ')))))

h3a_nat_pure_att_korea<-with(basedata[(basedata$TreatG | basedata$TreatA) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatG + ', paste(regions, '* TreatG', collapse = ' + ')))))
h3a_nat_reg_att_korea<-with(basedata[(basedata$TreatG | basedata$TreatB) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatG + ', paste(regions, '* TreatG', collapse = ' + ')))))
h3a_nat_pure_att_japan<-with(basedata[(basedata$TreatG | basedata$TreatA) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatG + ', paste(regions, '* TreatG', collapse = ' + ')))))
h3a_nat_reg_att_japan<-with(basedata[(basedata$TreatG | basedata$TreatB) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatG + ', paste(regions, '* TreatG', collapse = ' + ')))))

# Covariates

h3a_nat_pure_att_covar<-with(basedata[(basedata$TreatG | basedata$TreatA),], lm(as.formula(paste0('Attitude ~ TreatG + ', paste(covars, '* TreatG', collapse = ' + '), '+', paste(regions, '* TreatG', collapse = ' + ')))))
h3a_nat_reg_att_covar<-with(basedata[(basedata$TreatG | basedata$TreatB),], lm(as.formula(paste0('Attitude ~ TreatG + ', paste(covars, '* TreatG', collapse = ' + '), '+', paste(regions, '* TreatG', collapse = ' + ')))))
h3a_nat_pure_beh_covar<-with(basedata[(basedata$TreatG | basedata$TreatA),], lm(as.formula(paste0('Behavior ~ TreatG + ', paste(covars, '* TreatG', collapse = ' + '), '+', paste(regions, '* TreatG', collapse = ' + ')))))
h3a_nat_reg_beh_covar<-with(basedata[(basedata$TreatG | basedata$TreatB),], lm(as.formula(paste0('Behavior ~ TreatG + ', paste(covars, '* TreatG', collapse = ' + '), '+', paste(regions, '* TreatG', collapse = ' + ')))))

h3a_nat_pure_att_korea_covar<-with(basedata[(basedata$TreatG | basedata$TreatA) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatG + ', paste(covars, '* TreatG', collapse = ' + '), '+', paste(regions, '* TreatG', collapse = ' + ')))))
h3a_nat_reg_att_korea_covar<-with(basedata[(basedata$TreatG | basedata$TreatB) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatG + ', paste(covars, '* TreatG', collapse = ' + '), '+', paste(regions, '* TreatG', collapse = ' + ')))))
h3a_nat_pure_att_japan_covar<-with(basedata[(basedata$TreatG | basedata$TreatA) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatG + ', paste(covars, '* TreatG', collapse = ' + '), '+', paste(regions, '* TreatG', collapse = ' + ')))))
h3a_nat_reg_att_japan_covar<-with(basedata[(basedata$TreatG | basedata$TreatB) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatG + ', paste(covars, '* TreatG', collapse = ' + '), '+', paste(regions, '* TreatG', collapse = ' + ')))))

# Gather coefficients and confidence intervals

ci_level<-.9

ate_h3a_nat_pure_att<-sapply(list(h3a_nat_pure_att, h3a_nat_pure_att_korea,  h3a_nat_pure_att_japan), function(x) coef(x)[2])
ate_h3a_nat_pure_att_covar<-sapply(list(h3a_nat_pure_att_covar, h3a_nat_pure_att_korea_covar,  h3a_nat_pure_att_japan_covar), function(x) coef(x)[2])
ate_h3a_nat_reg_att<-sapply(list(h3a_nat_reg_att, h3a_nat_reg_att_korea,  h3a_nat_reg_att_japan), function(x) coef(x)[2])
ate_h3a_nat_reg_att_covar<-sapply(list(h3a_nat_reg_att_covar, h3a_nat_reg_att_korea_covar,  h3a_nat_reg_att_japan_covar), function(x) coef(x)[2])

ci_h3a_nat_pure_att<-sapply(list(h3a_nat_pure_att, h3a_nat_pure_att_korea,  h3a_nat_pure_att_japan), function(x) confint(x, level=ci_level)[2,])
ci_h3a_nat_pure_att_covar<-sapply(list(h3a_nat_pure_att_covar, h3a_nat_pure_att_korea_covar,  h3a_nat_pure_att_japan_covar), function(x) confint(x, level=ci_level)[2,])
ci_h3a_nat_reg_att<-sapply(list(h3a_nat_reg_att, h3a_nat_reg_att_korea,  h3a_nat_reg_att_japan), function(x) confint(x, level=ci_level)[2,])
ci_h3a_nat_reg_att_covar<-sapply(list(h3a_nat_reg_att_covar, h3a_nat_reg_att_korea_covar,  h3a_nat_reg_att_japan_covar), function(x) confint(x, level=ci_level)[2,])

# Appendix Figure 15

lwd<-2
adjust<-0.2
nvars<-length(ate_h3a_nat_pure_att)
cex<-1
cex.point<-1.5

pdf(file='h3a_nat_att.pdf',width=6.5,height=4.5)
par(mar=c(3,3,1,1)+.01)
plot(ate_h3a_nat_pure_att_covar, nvars:1+0.5*adjust, type='p',axes=F,frame.plot=T,xlab='',ylab='', pch=19,xlim=c(-.5,.5), ylim=c(1-1.5*adjust,nvars+1.5*adjust),main='',sub='',cex=cex.point)
Axis(side=1,at=seq(-.5, .5, 0.125),labels= seq(-.5, .5, 0.125),cex.axis=cex)
Axis(side=2,at=c((nvars+1):0),labels=c('','All','Korea','Japan',''),las=3,cex.axis=cex, tick=F)
abline(v=0,lwd=1,lty=2)
segments(ci_h3a_nat_pure_att_covar[1,],nvars:1+0.5*adjust, ci_h3a_nat_pure_att_covar[2,],nvars:1+0.5*adjust,lwd=lwd)
segments(ci_h3a_nat_pure_att[1,],nvars:1+1.5*adjust, ci_h3a_nat_pure_att[2,],nvars:1+1.5*adjust,lwd=lwd)
segments(ci_h3a_nat_reg_att[1,],nvars:1-0.5*adjust, ci_h3a_nat_reg_att[2,],nvars:1-0.5*adjust,lwd=lwd)
segments(ci_h3a_nat_reg_att_covar[1,],nvars:1-1.5*adjust, ci_h3a_nat_reg_att_covar[2,],nvars:1-1.5*adjust,lwd=lwd)
points(ate_h3a_nat_pure_att, nvars:1+1.5*adjust, pch=21, bg='white', cex=cex.point)
points(ate_h3a_nat_reg_att, nvars:1-0.5*adjust, pch=24, bg='white', cex=cex.point)
points(ate_h3a_nat_reg_att_covar, nvars:1-1.5*adjust, pch=17, cex=cex.point)
legend('topright',pch=c(21,19,24,17),legend=c('Pure / No','Pure / Yes','Regular / No','Regular / Yes'), title='Control / Covariates:', inset=0.04)
dev.off()

######################################################
# Testing H3b (no plots or country-specific estimates)
######################################################

# No Covariates

h3b_ideol_att<-with(basedata[(basedata$TreatE | basedata$TreatF),], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(regions, '* TreatE', collapse = ' + ')))))
h3b_nat_att<-with(basedata[(basedata$TreatE | basedata$TreatG),], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(regions, '* TreatE', collapse = ' + ')))))
h3b_ideol_beh<-with(basedata[(basedata$TreatE | basedata$TreatF),], lm(as.formula(paste0('Behavior ~ TreatE + ', paste(regions, '* TreatE', collapse = ' + ')))))
h3b_nat_beh<-with(basedata[(basedata$TreatE | basedata$TreatG),], lm(as.formula(paste0('Behavior ~ TreatE + ', paste(regions, '* TreatE', collapse = ' + ')))))

# Covariates

h3b_ideol_att_covar<-with(basedata[(basedata$TreatE | basedata$TreatF),], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(covars, '* TreatE', collapse = ' + '), '+', paste(regions, '* TreatE', collapse = ' + ')))))
h3b_nat_att_covar<-with(basedata[(basedata$TreatE | basedata$TreatG),], lm(as.formula(paste0('Attitude ~ TreatE + ', paste(covars, '* TreatE', collapse = ' + '), '+', paste(regions, '* TreatE', collapse = ' + ')))))
h3b_ideol_beh_covar<-with(basedata[(basedata$TreatE | basedata$TreatF),], lm(as.formula(paste0('Behavior ~ TreatE + ', paste(covars, '* TreatE', collapse = ' + '), '+', paste(regions, '* TreatE', collapse = ' + ')))))
h3b_nat_beh_covar<-with(basedata[(basedata$TreatE | basedata$TreatG),], lm(as.formula(paste0('Behavior ~ TreatE + ', paste(covars, '* TreatE', collapse = ' + '), '+', paste(regions, '* TreatE', collapse = ' + ')))))

############
# Testing H4
############

# No Covariates

h4_pure_att<-with(basedata[(basedata$TreatH | basedata$TreatA),], lm(as.formula(paste0('Attitude ~ TreatH + ', paste(regions, '* TreatH', collapse = ' + ')))))
h4_reg_att<-with(basedata[(basedata$TreatH | basedata$TreatB),], lm(as.formula(paste0('Attitude ~ TreatH + ', paste(regions, '* TreatH', collapse = ' + ')))))
h4_pure_beh<-with(basedata[(basedata$TreatH | basedata$TreatA),], lm(as.formula(paste0('Behavior ~ TreatH + ', paste(regions, '* TreatH', collapse = ' + ')))))
h4_reg_beh<-with(basedata[(basedata$TreatH | basedata$TreatB),], lm(as.formula(paste0('Behavior ~ TreatH + ', paste(regions, '* TreatH', collapse = ' + ')))))

h4_pure_att_korea<-with(basedata[(basedata$TreatH | basedata$TreatA) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatH + ', paste(regions, '* TreatH', collapse = ' + ')))))
h4_reg_att_korea<-with(basedata[(basedata$TreatH | basedata$TreatB) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatH + ', paste(regions, '* TreatH', collapse = ' + ')))))
h4_pure_att_japan<-with(basedata[(basedata$TreatH | basedata$TreatA) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatH + ', paste(regions, '* TreatH', collapse = ' + ')))))
h4_reg_att_japan<-with(basedata[(basedata$TreatH | basedata$TreatB) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatH + ', paste(regions, '* TreatH', collapse = ' + ')))))

# Covariates

h4_pure_att_covar<-with(basedata[(basedata$TreatH | basedata$TreatA),], lm(as.formula(paste0('Attitude ~ TreatH + ', paste(covars, '* TreatH', collapse = ' + '), '+', paste(regions, '* TreatH', collapse = ' + ')))))
h4_reg_att_covar<-with(basedata[(basedata$TreatH | basedata$TreatB),], lm(as.formula(paste0('Attitude ~ TreatH + ', paste(covars, '* TreatH', collapse = ' + '), '+', paste(regions, '* TreatH', collapse = ' + ')))))
h4_pure_beh_covar<-with(basedata[(basedata$TreatH | basedata$TreatA),], lm(as.formula(paste0('Behavior ~ TreatH + ', paste(covars, '* TreatH', collapse = ' + '), '+', paste(regions, '* TreatH', collapse = ' + ')))))
h4_reg_beh_covar<-with(basedata[(basedata$TreatH | basedata$TreatB),], lm(as.formula(paste0('Behavior ~ TreatH + ', paste(covars, '* TreatH', collapse = ' + '), '+', paste(regions, '* TreatH', collapse = ' + ')))))

h4_pure_att_korea_covar<-with(basedata[(basedata$TreatH | basedata$TreatA) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatH + ', paste(covars, '* TreatH', collapse = ' + '), '+', paste(regions, '* TreatH', collapse = ' + ')))))
h4_reg_att_korea_covar<-with(basedata[(basedata$TreatH | basedata$TreatB) & basedata$Country=='Korea',], lm(as.formula(paste0('Attitude ~ TreatH + ', paste(covars, '* TreatH', collapse = ' + '), '+', paste(regions, '* TreatH', collapse = ' + ')))))
h4_pure_att_japan_covar<-with(basedata[(basedata$TreatH | basedata$TreatA) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatH + ', paste(covars, '* TreatH', collapse = ' + '), '+', paste(regions, '* TreatH', collapse = ' + ')))))
h4_reg_att_japan_covar<-with(basedata[(basedata$TreatH | basedata$TreatB) & basedata$Country=='Japan',], lm(as.formula(paste0('Attitude ~ TreatH + ', paste(covars, '* TreatH', collapse = ' + '), '+', paste(regions, '* TreatH', collapse = ' + ')))))

# Gather coefficients and confidence intervals

ci_level<-.9

ate_h4_pure_att<-sapply(list(h4_pure_att, h4_pure_att_korea,  h4_pure_att_japan), function(x) coef(x)[2])
ate_h4_pure_att_covar<-sapply(list(h4_pure_att_covar, h4_pure_att_korea_covar,  h4_pure_att_japan_covar), function(x) coef(x)[2])
ate_h4_reg_att<-sapply(list(h4_reg_att, h4_reg_att_korea,  h4_reg_att_japan), function(x) coef(x)[2])
ate_h4_reg_att_covar<-sapply(list(h4_reg_att_covar, h4_reg_att_korea_covar,  h4_reg_att_japan_covar), function(x) coef(x)[2])

ci_h4_pure_att<-sapply(list(h4_pure_att, h4_pure_att_korea,  h4_pure_att_japan), function(x) confint(x, level=ci_level)[2,])
ci_h4_pure_att_covar<-sapply(list(h4_pure_att_covar, h4_pure_att_korea_covar,  h4_pure_att_japan_covar), function(x) confint(x, level=ci_level)[2,])
ci_h4_reg_att<-sapply(list(h4_reg_att, h4_reg_att_korea,  h4_reg_att_japan), function(x) confint(x, level=ci_level)[2,])
ci_h4_reg_att_covar<-sapply(list(h4_reg_att_covar, h4_reg_att_korea_covar,  h4_reg_att_japan_covar), function(x) confint(x, level=ci_level)[2,])

# Appendix Figure 16

lwd<-2
adjust<-0.2
nvars<-length(ate_h4_pure_att)
cex<-1
cex.point<-1.5

pdf(file='h4_att.pdf',width=6.5,height=4.5)
par(mar=c(3,3,1,1)+.01)
plot(ate_h4_pure_att_covar, nvars:1+0.5*adjust, type='p',axes=F,frame.plot=T,xlab='',ylab='', pch=19,xlim=c(-.5,.5), ylim=c(1-1.5*adjust,nvars+1.5*adjust),main='',sub='',cex=cex.point)
Axis(side=1,at=seq(-.5, .5, 0.125),labels= seq(-.5, .5, 0.125),cex.axis=cex)
Axis(side=2,at=c((nvars+1):0),labels=c('','All','Korea','Japan',''),las=3,cex.axis=cex, tick=F)
abline(v=0,lwd=1,lty=2)
segments(ci_h4_pure_att_covar[1,],nvars:1+0.5*adjust, ci_h4_pure_att_covar[2,],nvars:1+0.5*adjust,lwd=lwd)
segments(ci_h4_pure_att[1,],nvars:1+1.5*adjust, ci_h4_pure_att[2,],nvars:1+1.5*adjust,lwd=lwd)
segments(ci_h4_reg_att[1,],nvars:1-0.5*adjust, ci_h4_reg_att[2,],nvars:1-0.5*adjust,lwd=lwd)
segments(ci_h4_reg_att_covar[1,],nvars:1-1.5*adjust, ci_h4_reg_att_covar[2,],nvars:1-1.5*adjust,lwd=lwd)
points(ate_h4_pure_att, nvars:1+1.5*adjust, pch=21, bg='white', cex=cex.point)
points(ate_h4_reg_att, nvars:1-0.5*adjust, pch=24, bg='white', cex=cex.point)
points(ate_h4_reg_att_covar, nvars:1-1.5*adjust, pch=17, cex=cex.point)
legend('topleft',pch=c(21,19,24,17),legend=c('Pure / No','Pure / Yes','Regular / No','Regular / Yes'), title='Control / Covariates:', inset=0.04)
dev.off()

#####################################################
# Combo Plots (Main Text Figure 1, Appendix Figure 8)
#####################################################

# Gather coefficients and confidence intervals

ci_level<-.9

ate_pure_att<-sapply(list(h1_pure_att, h2_pure_att_neg, h2_pure_att_pos, h3a_prag_pure_att, h3a_ideol_pure_att, h3a_nat_pure_att, h4_pure_att), function(x)  coef(x)[2])
ate_pure_att_covar<-sapply(list(h1_pure_att_covar, h2_pure_att_neg_covar, h2_pure_att_pos_covar, h3a_prag_pure_att_covar, h3a_ideol_pure_att_covar, h3a_nat_pure_att_covar, h4_pure_att_covar), function(x)  coef(x)[2])
ate_reg_att<-sapply(list(h1_reg_att, h2_reg_att_neg, h2_reg_att_pos, h3a_prag_reg_att, h3a_ideol_reg_att, h3a_nat_reg_att, h4_reg_att), function(x)  coef(x)[2])
ate_reg_att_covar<-sapply(list(h1_reg_att_covar, h2_reg_att_neg_covar, h2_reg_att_pos_covar, h3a_prag_reg_att_covar, h3a_ideol_reg_att_covar, h3a_nat_reg_att_covar, h4_reg_att_covar), function(x)  coef(x)[2])

ci_pure_att<-sapply(list(h1_pure_att, h2_pure_att_neg, h2_pure_att_pos, h3a_prag_pure_att, h3a_ideol_pure_att, h3a_nat_pure_att, h4_pure_att), function(x) confint(x, level=ci_level)[2,])
ci_pure_att_covar<-sapply(list(h1_pure_att_covar, h2_pure_att_neg_covar, h2_pure_att_pos_covar, h3a_prag_pure_att_covar, h3a_ideol_pure_att_covar, h3a_nat_pure_att_covar, h4_pure_att_covar), function(x) confint(x, level=ci_level)[2,])
ci_reg_att<-sapply(list(h1_reg_att, h2_reg_att_neg, h2_reg_att_pos, h3a_prag_reg_att, h3a_ideol_reg_att, h3a_nat_reg_att, h4_reg_att), function(x) confint(x, level=ci_level)[2,])
ci_reg_att_covar<-sapply(list(h1_reg_att_covar, h2_reg_att_neg_covar, h2_reg_att_pos_covar, h3a_prag_reg_att_covar, h3a_ideol_reg_att_covar, h3a_nat_reg_att_covar, h4_reg_att_covar), function(x) confint(x, level=ci_level)[2,])

ate_pure_beh<-sapply(list(h1_pure_beh, h2_pure_beh_neg, h2_pure_beh_pos, h3a_prag_pure_beh, h3a_ideol_pure_beh, h3a_nat_pure_beh, h4_pure_beh), function(x)  coef(x)[2])
ate_pure_beh_covar<-sapply(list(h1_pure_beh_covar, h2_pure_beh_neg_covar, h2_pure_beh_pos_covar, h3a_prag_pure_beh_covar, h3a_ideol_pure_beh_covar, h3a_nat_pure_beh_covar, h4_pure_beh_covar), function(x)  coef(x)[2])
ate_reg_beh<-sapply(list(h1_reg_beh, h2_reg_beh_neg, h2_reg_beh_pos, h3a_prag_reg_beh, h3a_ideol_reg_beh, h3a_nat_reg_beh, h4_reg_beh), function(x)  coef(x)[2])
ate_reg_beh_covar<-sapply(list(h1_reg_beh_covar, h2_reg_beh_neg_covar, h2_reg_beh_pos_covar, h3a_prag_reg_beh_covar, h3a_ideol_reg_beh_covar, h3a_nat_reg_beh_covar, h4_reg_beh_covar), function(x)  coef(x)[2])

ci_pure_beh<-sapply(list(h1_pure_beh, h2_pure_beh_neg, h2_pure_beh_pos, h3a_prag_pure_beh, h3a_ideol_pure_beh, h3a_nat_pure_beh, h4_pure_beh), function(x) confint(x, level=ci_level)[2,])
ci_pure_beh_covar<-sapply(list(h1_pure_beh_covar, h2_pure_beh_neg_covar, h2_pure_beh_pos_covar, h3a_prag_pure_beh_covar, h3a_ideol_pure_beh_covar, h3a_nat_pure_beh_covar, h4_pure_beh_covar), function(x) confint(x, level=ci_level)[2,])
ci_reg_beh<-sapply(list(h1_reg_beh, h2_reg_beh_neg, h2_reg_beh_pos, h3a_prag_reg_beh, h3a_ideol_reg_beh, h3a_nat_reg_beh, h4_reg_beh), function(x) confint(x, level=ci_level)[2,])
ci_reg_beh_covar<-sapply(list(h1_reg_beh_covar, h2_reg_beh_neg_covar, h2_reg_beh_pos_covar, h3a_prag_reg_beh_covar, h3a_ideol_reg_beh_covar, h3a_nat_reg_beh_covar, h4_reg_beh_covar), function(x) confint(x, level=ci_level)[2,])

# Main Text Figure 1

lwd<-2
adjust<-0.15
nvars<-length(ate_pure_att)
cex<-1
cex.point<-1.5

pdf(file='combo_att.pdf',width=6.5,height=8)
par(mar=c(3,3,1,1)+.01)
plot(ate_pure_att_covar, nvars:1+0.5*adjust, type='p',axes=F,frame.plot=T,xlab='',ylab='', pch=19,xlim=c(-.5,.5), ylim=c(1-1.5*adjust,nvars+1.5*adjust),main='',sub='',cex=cex.point)
Axis(side=1,at=seq(-.5, .5, 0.125),labels= seq(-.5, .5, 0.125),cex.axis=cex)
Axis(side=2,at=c((nvars+1):0),labels=c('','Trigger\nEvents','Disruption:\nExpansion','Disruption:\nReduction','Pragmatic\nFraming','Ideological\nFraming','Nationalistic\nFraming','Local\nLeaders',''),las=3,cex.axis=cex, tick=F)
abline(v=0,lwd=1,lty=2)
segments(ci_pure_att_covar[1,],nvars:1+0.5*adjust, ci_pure_att_covar[2,],nvars:1+0.5*adjust,lwd=lwd)
segments(ci_pure_att[1,],nvars:1+1.5*adjust, ci_pure_att[2,],nvars:1+1.5*adjust,lwd=lwd)
segments(ci_reg_att[1,],nvars:1-0.5*adjust, ci_reg_att[2,],nvars:1-0.5*adjust,lwd=lwd)
segments(ci_reg_att_covar[1,],nvars:1-1.5*adjust, ci_reg_att_covar[2,],nvars:1-1.5*adjust,lwd=lwd)
points(ate_pure_att, nvars:1+1.5*adjust, pch=21, bg='white', cex=cex.point)
points(ate_reg_att, nvars:1-0.5*adjust, pch=24, bg='white', cex=cex.point)
points(ate_reg_att_covar, nvars:1-1.5*adjust, pch=17, cex=cex.point)
legend('topleft',pch=c(21,19,24,17),legend=c('Pure / No','Pure / Yes','Regular / No','Regular / Yes'), title='Control / Covariates:', inset=0.04)
dev.off()

# Appendix Figure 8

pdf(file='combo_beh.pdf',width=6.5,height=8)
par(mar=c(3,3,1,1)+.01)
plot(ate_pure_beh_covar, nvars:1+0.5*adjust, type='p',axes=F,frame.plot=T,xlab='',ylab='', pch=19,xlim=c(-.25,.25), ylim=c(1-1.5*adjust,nvars+1.5*adjust),main='',sub='',cex=cex.point)
Axis(side=1,at=seq(-.25, .25, 0.0625),labels= seq(-.25, .25, 0.0625),cex.axis=cex)
Axis(side=2,at=c((nvars+1):0),labels=c('','Trigger\nEvents','Disruption:\nExpansion','Disruption:\nReduction','Pragmatic\nFraming','Ideological\nFraming','Nationalistic\nFraming','Local\nLeaders',''),las=3,cex.axis=cex, tick=F)
abline(v=0,lwd=1,lty=2)
segments(ci_pure_beh_covar[1,],nvars:1+0.5*adjust, ci_pure_beh_covar[2,],nvars:1+0.5*adjust,lwd=lwd)
segments(ci_pure_beh[1,],nvars:1+1.5*adjust, ci_pure_beh[2,],nvars:1+1.5*adjust,lwd=lwd)
segments(ci_reg_beh[1,],nvars:1-0.5*adjust, ci_reg_beh[2,],nvars:1-0.5*adjust,lwd=lwd)
segments(ci_reg_beh_covar[1,],nvars:1-1.5*adjust, ci_reg_beh_covar[2,],nvars:1-1.5*adjust,lwd=lwd)
points(ate_pure_beh, nvars:1+1.5*adjust, pch=21, bg='white', cex=cex.point)
points(ate_reg_beh, nvars:1-0.5*adjust, pch=24, bg='white', cex=cex.point)
points(ate_reg_beh_covar, nvars:1-1.5*adjust, pch=17, cex=cex.point)
legend('topleft',pch=c(21,19,24,17),legend=c('Pure / No','Pure / Yes','Regular / No','Regular / Yes'), title='Control / Covariates:', inset=0.04)
dev.off()

################################
# Appendix Tables 3, 4, 5, and 6
################################

# Valid N

n_pure_att<-sapply(list(h1_pure_att, h2_pure_att_neg, h2_pure_att_pos, h3a_prag_pure_att, h3a_ideol_pure_att, h3a_nat_pure_att, h4_pure_att, h3b_ideol_att, h3b_nat_att), function(x)  x$rank + x$df.residual)
n_pure_att_covar<-sapply(list(h1_pure_att_covar, h2_pure_att_neg_covar, h2_pure_att_pos_covar, h3a_prag_pure_att_covar, h3a_ideol_pure_att_covar, h3a_nat_pure_att_covar, h4_pure_att_covar, h3b_ideol_att_covar, h3b_nat_att_covar), function(x)  x$rank + x$df.residual)
n_reg_att<-sapply(list(h1_reg_att, h2_reg_att_neg, h2_reg_att_pos, h3a_prag_reg_att, h3a_ideol_reg_att, h3a_nat_reg_att, h4_reg_att, h3b_ideol_att, h3b_nat_att), function(x)  x$rank + x$df.residual)
n_reg_att_covar<-sapply(list(h1_reg_att_covar, h2_reg_att_neg_covar, h2_reg_att_pos_covar, h3a_prag_reg_att_covar, h3a_ideol_reg_att_covar, h3a_nat_reg_att_covar, h4_reg_att_covar, h3b_ideol_att_covar, h3b_nat_att_covar), function(x)  x$rank + x$df.residual)

n_pure_beh<-sapply(list(h1_pure_beh, h2_pure_beh_neg, h2_pure_beh_pos, h3a_prag_pure_beh, h3a_ideol_pure_beh, h3a_nat_pure_beh, h4_pure_beh, h3b_ideol_beh, h3b_nat_beh), function(x)  x$rank + x$df.residual)
n_pure_beh_covar<-sapply(list(h1_pure_beh_covar, h2_pure_beh_neg_covar, h2_pure_beh_pos_covar, h3a_prag_pure_beh_covar, h3a_ideol_pure_beh_covar, h3a_nat_pure_beh_covar, h4_pure_beh_covar, h3b_ideol_beh_covar, h3b_nat_beh_covar), function(x)  x$rank + x$df.residual)
n_reg_beh<-sapply(list(h1_reg_beh, h2_reg_beh_neg, h2_reg_beh_pos, h3a_prag_reg_beh, h3a_ideol_reg_beh, h3a_nat_reg_beh, h4_reg_beh, h3b_ideol_beh, h3b_nat_beh), function(x)  x$rank + x$df.residual)
n_reg_beh_covar<-sapply(list(h1_reg_beh_covar, h2_reg_beh_neg_covar, h2_reg_beh_pos_covar, h3a_prag_reg_beh_covar, h3a_ideol_reg_beh_covar, h3a_nat_reg_beh_covar, h4_reg_beh_covar, h3b_ideol_beh_covar, h3b_nat_beh_covar), function(x)  x$rank + x$df.residual)

# Gather coefficients and standard errors

digits<-2

coef_pure_att<-round(sapply(list(h1_pure_att, h2_pure_att_neg, h2_pure_att_pos, h3a_prag_pure_att, h3a_ideol_pure_att, h3a_nat_pure_att, h4_pure_att, h3b_ideol_att, h3b_nat_att), function(x)  coef(x)[1:2]),digits)
coef_pure_att_covar<-round(sapply(list(h1_pure_att_covar, h2_pure_att_neg_covar, h2_pure_att_pos_covar, h3a_prag_pure_att_covar, h3a_ideol_pure_att_covar, h3a_nat_pure_att_covar, h4_pure_att_covar, h3b_ideol_att_covar, h3b_nat_att_covar), function(x)  coef(x)[1:2]),digits)
coef_reg_att<-round(sapply(list(h1_reg_att, h2_reg_att_neg, h2_reg_att_pos, h3a_prag_reg_att, h3a_ideol_reg_att, h3a_nat_reg_att, h4_reg_att, h3b_ideol_att, h3b_nat_att), function(x)  coef(x)[1:2]),digits)
coef_reg_att_covar<-round(sapply(list(h1_reg_att_covar, h2_reg_att_neg_covar, h2_reg_att_pos_covar, h3a_prag_reg_att_covar, h3a_ideol_reg_att_covar, h3a_nat_reg_att_covar, h4_reg_att_covar, h3b_ideol_att_covar, h3b_nat_att_covar), function(x)  coef(x)[1:2]),digits)

se_pure_att<-round(sapply(list(h1_pure_att, h2_pure_att_neg, h2_pure_att_pos, h3a_prag_pure_att, h3a_ideol_pure_att, h3a_nat_pure_att, h4_pure_att, h3b_ideol_att, h3b_nat_att), function(x) coef(summary(x))[1:2,'Std. Error']),digits)
se_pure_att_covar<-round(sapply(list(h1_pure_att_covar, h2_pure_att_neg_covar, h2_pure_att_pos_covar, h3a_prag_pure_att_covar, h3a_ideol_pure_att_covar, h3a_nat_pure_att_covar, h4_pure_att_covar, h3b_ideol_att_covar, h3b_nat_att_covar), function(x) coef(summary(x))[1:2,'Std. Error']),digits)
se_reg_att<-round(sapply(list(h1_reg_att, h2_reg_att_neg, h2_reg_att_pos, h3a_prag_reg_att, h3a_ideol_reg_att, h3a_nat_reg_att, h4_reg_att, h3b_ideol_att, h3b_nat_att), function(x) coef(summary(x))[1:2,'Std. Error']),digits)
se_reg_att_covar<-round(sapply(list(h1_reg_att_covar, h2_reg_att_neg_covar, h2_reg_att_pos_covar, h3a_prag_reg_att_covar, h3a_ideol_reg_att_covar, h3a_nat_reg_att_covar, h4_reg_att_covar, h3b_ideol_att_covar, h3b_nat_att_covar), function(x) coef(summary(x))[1:2,'Std. Error']),digits)

se_pure_att<-apply(se_pure_att,2,function(x) paste0('(',x,')'))
se_pure_att_covar<-apply(se_pure_att_covar,2,function(x) paste0('(',x,')'))
se_reg_att<-apply(se_reg_att,2,function(x) paste0('(',x,')'))
se_reg_att_covar<-apply(se_reg_att_covar,2,function(x) paste0('(',x,')'))

coef_pure_beh<-round(sapply(list(h1_pure_beh, h2_pure_beh_neg, h2_pure_beh_pos, h3a_prag_pure_beh, h3a_ideol_pure_beh, h3a_nat_pure_beh, h4_pure_beh, h3b_ideol_beh, h3b_nat_beh), function(x)  coef(x)[1:2]),digits)
coef_pure_beh_covar<-round(sapply(list(h1_pure_beh_covar, h2_pure_beh_neg_covar, h2_pure_beh_pos_covar, h3a_prag_pure_beh_covar, h3a_ideol_pure_beh_covar, h3a_nat_pure_beh_covar, h4_pure_beh_covar, h3b_ideol_beh_covar, h3b_nat_beh_covar), function(x)  coef(x)[1:2]),digits)
coef_reg_beh<-round(sapply(list(h1_reg_beh, h2_reg_beh_neg, h2_reg_beh_pos, h3a_prag_reg_beh, h3a_ideol_reg_beh, h3a_nat_reg_beh, h4_reg_beh, h3b_ideol_beh, h3b_nat_beh), function(x)  coef(x)[1:2]),digits)
coef_reg_beh_covar<-round(sapply(list(h1_reg_beh_covar, h2_reg_beh_neg_covar, h2_reg_beh_pos_covar, h3a_prag_reg_beh_covar, h3a_ideol_reg_beh_covar, h3a_nat_reg_beh_covar, h4_reg_beh_covar, h3b_ideol_beh_covar, h3b_nat_beh_covar), function(x)  coef(x)[1:2]),digits)

se_pure_beh<-round(sapply(list(h1_pure_beh, h2_pure_beh_neg, h2_pure_beh_pos, h3a_prag_pure_beh, h3a_ideol_pure_beh, h3a_nat_pure_beh, h4_pure_beh, h3b_ideol_beh, h3b_nat_beh), function(x) coef(summary(x))[1:2,'Std. Error']),digits)
se_pure_beh_covar<-round(sapply(list(h1_pure_beh_covar, h2_pure_beh_neg_covar, h2_pure_beh_pos_covar, h3a_prag_pure_beh_covar, h3a_ideol_pure_beh_covar, h3a_nat_pure_beh_covar, h4_pure_beh_covar, h3b_ideol_beh_covar, h3b_nat_beh_covar), function(x) coef(summary(x))[1:2,'Std. Error']),digits)
se_reg_beh<-round(sapply(list(h1_reg_beh, h2_reg_beh_neg, h2_reg_beh_pos, h3a_prag_reg_beh, h3a_ideol_reg_beh, h3a_nat_reg_beh, h4_reg_beh, h3b_ideol_beh, h3b_nat_beh), function(x) coef(summary(x))[1:2,'Std. Error']),digits)
se_reg_beh_covar<-round(sapply(list(h1_reg_beh_covar, h2_reg_beh_neg_covar, h2_reg_beh_pos_covar, h3a_prag_reg_beh_covar, h3a_ideol_reg_beh_covar, h3a_nat_reg_beh_covar, h4_reg_beh_covar, h3b_ideol_beh_covar, h3b_nat_beh_covar), function(x) coef(summary(x))[1:2,'Std. Error']),digits)

se_pure_beh<-apply(se_pure_beh,2,function(x) paste0('(',x,')'))
se_pure_beh_covar<-apply(se_pure_beh_covar,2,function(x) paste0('(',x,')'))
se_reg_beh<-apply(se_reg_beh,2,function(x) paste0('(',x,')'))
se_reg_beh_covar<-apply(se_reg_beh_covar,2,function(x) paste0('(',x,')'))

# Organize results into tables

table.pure.att<-matrix(c(coef_pure_att[1,],se_pure_att[1,],coef_pure_att[2,],se_pure_att[2,],coef_pure_att_covar[1,],se_pure_att_covar[1,],coef_pure_att_covar[2,],se_pure_att_covar[2,],n_pure_att),nrow=9,byrow=T)
table.reg.att<-matrix(c(coef_reg_att[1,],se_reg_att[1,],coef_reg_att[2,],se_reg_att[2,],coef_reg_att_covar[1,],se_reg_att_covar[1,],coef_reg_att_covar[2,],se_reg_att_covar[2,],n_reg_att),nrow=9,byrow=T)
table.pure.beh<-matrix(c(coef_pure_beh[1,],se_pure_beh[1,],coef_pure_beh[2,],se_pure_beh[2,],coef_pure_beh_covar[1,],se_pure_beh_covar[1,],coef_pure_beh_covar[2,],se_pure_beh_covar[2,],n_pure_beh),nrow=9,byrow=T)
table.reg.beh<-matrix(c(coef_reg_beh[1,],se_reg_beh[1,],coef_reg_beh[2,],se_reg_beh[2,],coef_reg_beh_covar[1,],se_reg_beh_covar[1,],coef_reg_beh_covar[2,],se_reg_beh_covar[2,],n_reg_beh),nrow=9,byrow=T)

colnames(table.pure.att)<-c('Trigger\nEvents','Disruption:\nExpansion','Disruption:\nReduction','Pragmatic\nFraming','Ideological\nFraming','Nationalistic\nFraming','Local\nLeaders','Pragmatic--\nIdeological','Pragmatic--\nNationalistic')
rownames(table.pure.att)<-c(rep(c('Intercept','','Treatment',''),2),'N')
colnames(table.reg.att)<-c('Trigger\nEvents','Disruption:\nExpansion','Disruption:\nReduction','Pragmatic\nFraming','Ideological\nFraming','Nationalistic\nFraming','Local\nLeaders','Pragmatic--\nIdeological','Pragmatic--\nNationalistic')
rownames(table.reg.att)<-c(rep(c('Intercept','','Treatment',''),2),'N')
colnames(table.pure.beh)<-c('Trigger\nEvents','Disruption:\nExpansion','Disruption:\nReduction','Pragmatic\nFraming','Ideological\nFraming','Nationalistic\nFraming','Local\nLeaders','Pragmatic--\nIdeological','Pragmatic--\nNationalistic')
rownames(table.pure.beh)<-c(rep(c('Intercept','','Treatment',''),2),'N')
colnames(table.reg.beh)<-c('Trigger\nEvents','Disruption:\nExpansion','Disruption:\nReduction','Pragmatic\nFraming','Ideological\nFraming','Nationalistic\nFraming','Local\nLeaders','Pragmatic--\nIdeological','Pragmatic--\nNationalistic')
rownames(table.reg.beh)<-c(rep(c('Intercept','','Treatment',''),2),'N')

results.table.att.note<-"\\small NOTE: Dependent variable is a 1--5 Likert scale measuring opposition to U.S. military bases in the respondent's region. Estimated standard errors in parentheses. Regional fixed effects not shown."

results.table.beh.note<-'\\small NOTE: Dependent variable is the proportion of prize money that the respondent agreed to donate to a Korean or Japanese anti-base organization in the event of winning the raffle. Estimated standard errors in parentheses. Regional fixed effects not shown.'

# Appendix Table 3

table.pure.att.latex<-latex(table.pure.att,file='table_pure_att.tex', rowlabel = '', collabel.just=rep('c',ncol(table.pure.att)), col.just=rep('c',ncol(table.pure.att)), extracolsize='normalsize',rgroup=c('Covariates: No','Covariates: Yes',''), n.rgroup=c(4,4,1), cgroup=c('Treatment','Differences'), n.cgroup=c(7,2),caption = 'Average Treatment Effects on Attitudinal Outcome Versus Pure Control', insert.bottom= results.table.att.note, booktabs = F, ctable = T, where = "htp", landscape=T, size='normalsize')

# Appendix Table 4

table.reg.att.latex<-latex(table.reg.att,file='table_reg_att.tex', rowlabel = '', collabel.just=rep('c',ncol(table.reg.att)), col.just=rep('c',ncol(table.reg.att)), extracolsize='normalsize',rgroup=c('Covariates: No','Covariates: Yes',''), n.rgroup=c(4,4,1), cgroup=c('Treatment','Differences'), n.cgroup=c(7,2),caption = 'Average Treatment Effects on Attitudinal Outcome Versus Regular Control', insert.bottom= results.table.att.note, booktabs = F, ctable = T, where = "htp", landscape=T, size='normalsize')

# Appendix Table 5

table.pure.beh.latex<-latex(table.pure.beh,file='table_pure_beh.tex', rowlabel = '', collabel.just=rep('c',ncol(table.pure.beh)), col.just=rep('c',ncol(table.pure.beh)), extracolsize='normalsize',rgroup=c('Covariates: No','Covariates: Yes',''), n.rgroup=c(4,4,1), cgroup=c('Treatment','Differences'), n.cgroup=c(7,2),caption = 'Average Treatment Effects on Behavioral Outcome Versus Pure Control', insert.bottom= results.table.beh.note, booktabs = F, ctable = T, where = "htp", landscape=T, size='normalsize')

# Appendix Table 6

table.reg.beh.latex<-latex(table.reg.beh,file='table_reg_beh.tex', rowlabel = '', collabel.just=rep('c',ncol(table.reg.beh)), col.just=rep('c',ncol(table.reg.beh)), extracolsize='normalsize',rgroup=c('Covariates: No','Covariates: Yes',''), n.rgroup=c(4,4,1), cgroup=c('Treatment','Differences'), n.cgroup=c(7,2),caption = 'Average Treatment Effects on Behavioral Outcome Versus Regular Control', insert.bottom= results.table.beh.note, booktabs = F, ctable = T, where = "htp", landscape=T, size='normalsize')


####################################
# Appendix Table 7 and Figures 17-18
####################################

h3a_ideol_pure_att_inter<-with(basedata[(basedata$TreatF | basedata$TreatA),], lm(as.formula(paste0('Attitude ~ TreatF * demean(Ideology) + ', paste(regions, '* TreatF * demean(Ideology)', collapse = ' + ')))))
h3a_ideol_reg_att_inter<-with(basedata[(basedata$TreatF | basedata$TreatB),], lm(as.formula(paste0('Attitude ~ TreatF * demean(Ideology) + ', paste(regions, '* TreatF * demean(Ideology)', collapse = ' + ')))))
h3a_nat_pure_att_inter<-with(basedata[(basedata$TreatG | basedata$TreatA),], lm(as.formula(paste0('Attitude ~ TreatG * demean(Ideology) + ', paste(regions, '* TreatG * demean(Ideology)', collapse = ' + ')))))
h3a_nat_reg_att_inter<-with(basedata[(basedata$TreatG | basedata$TreatB),], lm(as.formula(paste0('Attitude ~ TreatG * demean(Ideology) + ', paste(regions, '* TreatG * demean(Ideology)', collapse = ' + ')))))

# Gather coefficients, standard errors, and valid N

coef_att_inter<-round(sapply(list(h3a_ideol_pure_att_inter, h3a_nat_pure_att_inter, h3a_ideol_reg_att_inter, h3a_nat_reg_att_inter), function(x)  coef(x)[c(1:2,which(names(coef(x))=='demean(Ideology)'), which(names(coef(x))==paste(names(coef(x))[2],'demean(Ideology)',sep=':')))]),digits)
coef_att_inter_covar<-round(sapply(list(h3a_ideol_pure_att_covar, h3a_nat_pure_att_covar, h3a_ideol_reg_att_covar, h3a_nat_reg_att_covar), function(x)  coef(x)[c(1:2,which(names(coef(x))=='demean(Ideology)'), which(names(coef(x))==paste(names(coef(x))[2],'demean(Ideology)',sep=':')))]),digits)

se_att_inter<-round(sapply(list(h3a_ideol_pure_att_inter, h3a_nat_pure_att_inter, h3a_ideol_reg_att_inter, h3a_nat_reg_att_inter), function(x)  coef(summary(x))[c(1:2,which(rownames(coef(summary(x)))=='demean(Ideology)'), which(rownames(coef(summary(x)))==paste(rownames(coef(summary(x)))[2],'demean(Ideology)',sep=':'))),'Std. Error']),digits)
se_att_inter_covar<-round(sapply(list(h3a_ideol_pure_att_covar, h3a_nat_pure_att_covar, h3a_ideol_reg_att_covar, h3a_nat_reg_att_covar), function(x)  coef(summary(x))[c(1:2,which(rownames(coef(summary(x)))=='demean(Ideology)'), which(rownames(coef(summary(x)))==paste(rownames(coef(summary(x)))[2],'demean(Ideology)',sep=':'))),'Std. Error']),digits)

se_att_inter <-apply(se_att_inter,2,function(x) paste0('(',x,')'))
se_att_inter_covar <-apply(se_att_inter_covar,2,function(x) paste0('(',x,')'))

n_att_inter<-sapply(list(h3a_ideol_pure_att_inter, h3a_nat_pure_att_inter, h3a_ideol_reg_att_inter, h3a_nat_reg_att_inter), function(x)  x$rank + x$df.residual)

# Organize results into a table

table.att.inter<-matrix(c(coef_att_inter[1,], se_att_inter[1,], coef_att_inter[2,], se_att_inter[2,], coef_att_inter[3,], se_att_inter[3,], coef_att_inter[4,], se_att_inter[4,], coef_att_inter_covar[1,], se_att_inter_covar[1,], coef_att_inter_covar[2,], se_att_inter_covar[2,], coef_att_inter_covar[3,], se_att_inter_covar[3,], coef_att_inter_covar[4,], se_att_inter_covar[4,], n_att_inter), nrow=17,byrow=T)

colnames(table.att.inter)<-rep(c('Ideological\nFraming','Nationalistic\nFraming'),2)
rownames(table.att.inter)<-c(rep(c('Intercept','','Treatment','','Ideology','','Treatment $\\times$','Ideology'),2),'N')

results.table.att.inter.note<-"\\small NOTE: Dependent variable is a 1--5 Likert scale measuring opposition to U.S. military bases in the respondent's region. Estimated standard errors in parentheses. Regional fixed effects not shown. Ideology is demeaned, so the constitutive term of the interaction represents the effect for respondents of average ideology."

# Appendix Table 7

table.pure.att.latex<-latex(table.att.inter,file='table_att_inter.tex', rowlabel = '', collabel.just=rep('c',ncol(table.att.inter)), col.just=rep('c',ncol(table.att.inter)), extracolsize='normalsize',rgroup=c('Covariates: No','Covariates: Yes',''), n.rgroup=c(8,8,1), cgroup=c('Treatment vs. Pure Control','Treatment vs. Regular Control'), n.cgroup=c(2,2),caption = 'Average Treatment Effects on Attitudinal Outcome, Conditional on Ideology', insert.bottom= results.table.att.inter.note, booktabs = F, ctable = T, where = "htp", landscape=F, size='normalsize')

# Generate figures for interaction plots

ideol.vals<-seq(round(min(demean(basedata$Ideology)),2), round(max(demean(basedata$Ideology)),2),0.01)

point_est_ideol_pure_inter<-coef_att_inter[2,1] + coef_att_inter[4,1]*ideol.vals
point_est_nat_pure_inter<-coef_att_inter[2,2] + coef_att_inter[4,2]*ideol.vals
point_est_ideol_reg_inter<-coef_att_inter[2,3] + coef_att_inter[4,3]*ideol.vals
point_est_nat_reg_inter<-coef_att_inter[2,4] + coef_att_inter[4,4]*ideol.vals
point_est_ideol_pure_inter_covar<-coef_att_inter_covar[2,1] + coef_att_inter_covar[4,1]*ideol.vals
point_est_nat_pure_inter_covar<-coef_att_inter_covar[2,2] + coef_att_inter_covar[4,2]*ideol.vals
point_est_ideol_reg_inter_covar<-coef_att_inter_covar[2,3] + coef_att_inter_covar[4,3]*ideol.vals
point_est_nat_reg_inter_covar<-coef_att_inter_covar[2,4] + coef_att_inter_covar[4,4]*ideol.vals

std_err_ideol_pure_inter<-sqrt(vcov(h3a_ideol_pure_att_inter)['TreatFTRUE','TreatFTRUE'] + ideol.vals^2 * vcov(h3a_ideol_pure_att_inter)['TreatFTRUE:demean(Ideology)','TreatFTRUE:demean(Ideology)'] + 2 * ideol.vals * vcov(h3a_ideol_pure_att_inter)['TreatFTRUE','TreatFTRUE:demean(Ideology)'])
std_err_nat_pure_inter<-sqrt(vcov(h3a_nat_pure_att_inter)['TreatGTRUE','TreatGTRUE'] + ideol.vals^2 * vcov(h3a_nat_pure_att_inter)['TreatGTRUE:demean(Ideology)','TreatGTRUE:demean(Ideology)'] + 2 * ideol.vals * vcov(h3a_nat_pure_att_inter)['TreatGTRUE','TreatGTRUE:demean(Ideology)'])
std_err_ideol_reg_inter<-sqrt(vcov(h3a_ideol_reg_att_inter)['TreatFTRUE','TreatFTRUE'] + ideol.vals^2 * vcov(h3a_ideol_reg_att_inter)['TreatFTRUE:demean(Ideology)','TreatFTRUE:demean(Ideology)'] + 2 * ideol.vals * vcov(h3a_ideol_reg_att_inter)['TreatFTRUE','TreatFTRUE:demean(Ideology)'])
std_err_nat_reg_inter<-sqrt(vcov(h3a_nat_reg_att_inter)['TreatGTRUE','TreatGTRUE'] + ideol.vals^2 * vcov(h3a_nat_reg_att_inter)['TreatGTRUE:demean(Ideology)','TreatGTRUE:demean(Ideology)'] + 2 * ideol.vals * vcov(h3a_nat_reg_att_inter)['TreatGTRUE','TreatGTRUE:demean(Ideology)'])
std_err_ideol_pure_inter_covar<-sqrt(vcov(h3a_ideol_pure_att_covar)['TreatFTRUE','TreatFTRUE'] + ideol.vals^2 * vcov(h3a_ideol_pure_att_covar)['TreatFTRUE:demean(Ideology)','TreatFTRUE:demean(Ideology)'] + 2 * ideol.vals * vcov(h3a_ideol_pure_att_covar)['TreatFTRUE','TreatFTRUE:demean(Ideology)'])
std_err_nat_pure_inter_covar<-sqrt(vcov(h3a_nat_pure_att_covar)['TreatGTRUE','TreatGTRUE'] + ideol.vals^2 * vcov(h3a_nat_pure_att_covar)['TreatGTRUE:demean(Ideology)','TreatGTRUE:demean(Ideology)'] + 2 * ideol.vals * vcov(h3a_nat_pure_att_covar)['TreatGTRUE','TreatGTRUE:demean(Ideology)'])
std_err_ideol_reg_inter_covar<-sqrt(vcov(h3a_ideol_reg_att_covar)['TreatFTRUE','TreatFTRUE'] + ideol.vals^2 * vcov(h3a_ideol_reg_att_covar)['TreatFTRUE:demean(Ideology)','TreatFTRUE:demean(Ideology)'] + 2 * ideol.vals * vcov(h3a_ideol_reg_att_covar)['TreatFTRUE','TreatFTRUE:demean(Ideology)'])
std_err_nat_reg_inter_covar<-sqrt(vcov(h3a_nat_reg_att_covar)['TreatGTRUE','TreatGTRUE'] + ideol.vals^2 * vcov(h3a_nat_reg_att_covar)['TreatGTRUE:demean(Ideology)','TreatGTRUE:demean(Ideology)'] + 2 * ideol.vals * vcov(h3a_nat_reg_att_covar)['TreatGTRUE','TreatGTRUE:demean(Ideology)'])

# Appendix Figure 17

pdf(file='conditional_effects_nocovar.pdf',width=6.5,height=8)
par(mfrow=c(2,2))

par(mar=c(4,4,4,1))
plot(ideol.vals, point_est_ideol_pure_inter, ylim=c(-1,1), type='l', lwd=2, xaxt='n', ylab='Conditional Effect', xlab='Ideology', main='Ideological vs. Pure Control')
Axis(side=1,at=1:10-mean(basedata$Ideology),labels=1:10)
Axis(side=1,at=c(1.5,9.5)-mean(basedata$Ideology),labels=c('Left','Right'),line=2,lwd=0)
abline(h=0,lty=2,lwd=2)
lines(ideol.vals, point_est_ideol_pure_inter + qt(.975, h3a_ideol_pure_att_inter$df.residual)* std_err_ideol_pure_inter,lty=3,lwd=2)
lines(ideol.vals, point_est_ideol_pure_inter - qt(.975, h3a_ideol_pure_att_inter$df.residual)* std_err_ideol_pure_inter,lty=3,lwd=2)

par(mar=c(4,2,4,3))
plot(ideol.vals, point_est_nat_pure_inter, ylim=c(-1,1), type='l', lwd=2, xaxt='n', ylab='', xlab='Ideology', main='Nationalistic vs. Pure Control')
Axis(side=1,at=1:10-mean(basedata$Ideology),labels=1:10)
Axis(side=1,at=c(1.5,9.5)-mean(basedata$Ideology),labels=c('Left','Right'),line=2,lwd=0)
abline(h=0,lty=2,lwd=2)
lines(ideol.vals, point_est_nat_pure_inter + qt(.975, h3a_nat_pure_att_inter$df.residual)* std_err_nat_pure_inter,lty=3,lwd=2)
lines(ideol.vals, point_est_nat_pure_inter - qt(.975, h3a_nat_pure_att_inter$df.residual)* std_err_nat_pure_inter,lty=3,lwd=2)

par(mar=c(4,4,4,1))
plot(ideol.vals, point_est_ideol_reg_inter, ylim=c(-1,1), type='l', lwd=2, xaxt='n', ylab='Conditional Effect', xlab='Ideology', main='Ideological vs. Regular Control')
Axis(side=1,at=1:10-mean(basedata$Ideology),labels=1:10)
Axis(side=1,at=c(1.5,9.5)-mean(basedata$Ideology),labels=c('Left','Right'),line=2,lwd=0)
abline(h=0,lty=2,lwd=2)
lines(ideol.vals, point_est_ideol_reg_inter + qt(.975, h3a_ideol_reg_att_inter$df.residual)* std_err_ideol_reg_inter,lty=3,lwd=2)
lines(ideol.vals, point_est_ideol_reg_inter - qt(.975, h3a_ideol_reg_att_inter$df.residual)* std_err_ideol_reg_inter,lty=3,lwd=2)

par(mar=c(4,2,4,3))
plot(ideol.vals, point_est_nat_reg_inter, ylim=c(-1,1), type='l', lwd=2, xaxt='n', ylab='', xlab='Ideology', main='Nationalistic vs. Regular Control')
Axis(side=1,at=1:10-mean(basedata$Ideology),labels=1:10)
Axis(side=1,at=c(1.5,9.5)-mean(basedata$Ideology),labels=c('Left','Right'),line=2,lwd=0)
abline(h=0,lty=2,lwd=2)
lines(ideol.vals, point_est_nat_reg_inter + qt(.975, h3a_nat_reg_att_inter$df.residual)* std_err_nat_reg_inter,lty=3,lwd=2)
lines(ideol.vals, point_est_nat_reg_inter - qt(.975, h3a_nat_reg_att_inter$df.residual)* std_err_nat_reg_inter,lty=3,lwd=2)

dev.off()

# Appendix Figure 18

pdf(file='conditional_effects_covar.pdf',width=6.5,height=8)
par(mfrow=c(2,2))

par(mar=c(4,4,4,1))
plot(ideol.vals, point_est_ideol_pure_inter_covar, ylim=c(-1,1), type='l', lwd=2, xaxt='n', ylab='Conditional Effect', xlab='Ideology', main='Ideological vs. Pure Control')
Axis(side=1,at=1:10-mean(basedata$Ideology),labels=1:10)
Axis(side=1,at=c(1.5,9.5)-mean(basedata$Ideology),labels=c('Left','Right'),line=2,lwd=0)
abline(h=0,lty=2,lwd=2)
lines(ideol.vals, point_est_ideol_pure_inter_covar + qt(.975, h3a_ideol_pure_att_covar$df.residual)* std_err_ideol_pure_inter_covar,lty=3,lwd=2)
lines(ideol.vals, point_est_ideol_pure_inter_covar - qt(.975, h3a_ideol_pure_att_covar$df.residual)* std_err_ideol_pure_inter_covar,lty=3,lwd=2)

par(mar=c(4,2,4,3))
plot(ideol.vals, point_est_nat_pure_inter_covar, ylim=c(-1,1), type='l', lwd=2, xaxt='n', ylab='', xlab='Ideology', main='Nationalistic vs. Pure Control')
Axis(side=1,at=1:10-mean(basedata$Ideology),labels=1:10)
Axis(side=1,at=c(1.5,9.5)-mean(basedata$Ideology),labels=c('Left','Right'),line=2,lwd=0)
abline(h=0,lty=2,lwd=2)
lines(ideol.vals, point_est_nat_pure_inter_covar + qt(.975, h3a_nat_pure_att_covar$df.residual)* std_err_nat_pure_inter_covar,lty=3,lwd=2)
lines(ideol.vals, point_est_nat_pure_inter_covar - qt(.975, h3a_nat_pure_att_covar$df.residual)* std_err_nat_pure_inter_covar,lty=3,lwd=2)

par(mar=c(4,4,4,1))
plot(ideol.vals, point_est_ideol_reg_inter_covar, ylim=c(-1,1), type='l', lwd=2, xaxt='n', ylab='Conditional Effect', xlab='Ideology', main='Ideological vs. Regular Control')
Axis(side=1,at=1:10-mean(basedata$Ideology),labels=1:10)
Axis(side=1,at=c(1.5,9.5)-mean(basedata$Ideology),labels=c('Left','Right'),line=2,lwd=0)
abline(h=0,lty=2,lwd=2)
lines(ideol.vals, point_est_ideol_reg_inter_covar + qt(.975, h3a_ideol_reg_att_covar$df.residual)* std_err_ideol_reg_inter_covar,lty=3,lwd=2)
lines(ideol.vals, point_est_ideol_reg_inter_covar - qt(.975, h3a_ideol_reg_att_covar$df.residual)* std_err_ideol_reg_inter_covar,lty=3,lwd=2)

par(mar=c(4,2,4,3))
plot(ideol.vals, point_est_nat_reg_inter_covar, ylim=c(-1,1), type='l', lwd=2, xaxt='n', ylab='', xlab='Ideology', main='Nationalistic vs. Regular Control')
Axis(side=1,at=1:10-mean(basedata$Ideology),labels=1:10)
Axis(side=1,at=c(1.5,9.5)-mean(basedata$Ideology),labels=c('Left','Right'),line=2,lwd=0)
abline(h=0,lty=2,lwd=2)
lines(ideol.vals, point_est_nat_reg_inter_covar + qt(.975, h3a_nat_reg_att_covar$df.residual)* std_err_nat_reg_inter_covar,lty=3,lwd=2)
lines(ideol.vals, point_est_nat_reg_inter_covar - qt(.975, h3a_nat_reg_att_covar$df.residual)* std_err_nat_reg_inter_covar,lty=3,lwd=2)

dev.off()

###########################################################################
# Behavioral Outcome Raffle Donation: Appendix Figure 7 and textual results
###########################################################################

# Appendix Figure 7

pdf(file='donation.pdf',width=7.5,height=4.5)
par(mfrow=c(1,2))
hist(basedata$Behavior[basedata$Country=='Japan'],col='grey', xlab='Proportion of Prize Donated',main='Japan',ylim=c(0,800))
hist(basedata$Behavior[basedata$Country=='Korea'],col='grey', xlab='Proportion of Prize Donated',main='Korea',ylim=c(0,800))
dev.off()

# "All respondents had the option of entering a raffle for a 1-in-80 chance of winning a cash prize of 50,000 KRW or 5,000 JPY (each about $45); 94% did so in South Korea, and 82% did so in Japan."

prop.table(table(basedata$Country,basedata$Q36),1)

# "When asked, pre-treatment, to place each organization on a 1-10 left-right ideological scale, respondents gave similar answers in each country, averaging 3.88 in Korea and 3.75 in Japan (p = 0.17 for a two-tailed difference in means t-test)."

mean(basedata$Q16,na.rm=T) # Korea
mean(basedata$Q20,na.rm=T) # Japan
t.test(basedata$Q16, basedata$Q20)

# "In each country, the modal proportion donated was zero, but this option was much more commonly chosen in Japan (72% of respondents) than in Korea (40%)."

prop.table(table(basedata$Behavior[basedata$Country=='Japan']))
prop.table(table(basedata$Behavior[basedata$Country=='Korea']))

# "When asked in our survey about 'donating money to a civic group that shares causes I support' (towards the beginning of the survey and prior to any mention of U.S. military bases), 33% of Japanese respondents said that they would never do so, versus 8% of Koreans."

prop.table(table(basedata$Donate[basedata$Country=='Japan']))
prop.table(table(basedata$Donate[basedata$Country=='Korea']))

# "Thus, while respondents in both countries were similar in terms of their ideological placement of the anti-base organization, they placed themselves much further from this organization in Japan than in Korea (2.5 versus 1.9 points on the 1–10 scale; p < 0.001 for a two-tailed difference in means t-test)."

t.test(basedata$Distance_org[basedata$Country=='Japan'], basedata$Distance_org[basedata$Country=='Korea'])

#######################################
# Appendix Figure 2 and textual results
#######################################

basedata$Duration<-as.numeric(basedata$Duration)
basedata$Minutes<-basedata$Duration/60

pdf(file='duration.pdf',width=6,height=4.5)
par(mar=c(5,4,1,1)+.01)
hist(basedata$Minutes[basedata$Minutes < 30],breaks=20,col='lightgrey',xlab='Duration in Minutes',main='')
dev.off()

# "In contrast, the minimum survey duration was 1 minute 50 seconds, the first quartile was 4 minutes 39 seconds, and the median was 6 minutes 4 seconds."

summary(basedata$Duration)

##################
# Appendix Table 2
##################

n.tab<-table(basedata$Q30_cond,basedata$Region)
n.tab<-cbind(n.tab,apply(n.tab, 1, sum))
colnames(n.tab)[ncol(n.tab)]<-'Total'
n.tab<-rbind(colnames(n.tab),n.tab,apply(n.tab, 2, sum))
n.tab<-cbind(c('Condition','\\hline Pure Control','Regular Control','Trigger Events','Status Quo Disruption','Pragmatic Framing','Ideological Framing','Nationalistic Framing','Local Defiance','\\hline Total'),n.tab)
write.table(n.tab, file='n_tab.tex', sep=' & ', eol= '\\\\\n', row.names=F, col.names=F, quote=F)

##################################
# Other results reported textually
##################################

# "The hypothesis on base expansion (H2a) found strong support, with a statistically significant increase in opposition to U.S. bases in three out of four specifications. Across the four specifications, the average point estimate was 0.20. Pragmatic framing of opposition to U.S. bases by social movements (H3a) had similar, albeit slightly more moderate effects: an average point estimate of 0.17, significant in two out of four specifications. These effects are not particularly large compared to the distribution of the outcome variable, which has a standard deviation of 1.24, but they are detectable."

# "Reminding respondents of trigger events (H1) seems to have some small effect on opposition to U.S. bases--an average point estimate of 0.13."

apply(cbind(ate_pure_att, ate_pure_att_covar, ate_reg_att, ate_reg_att_covar),1,mean)
sd(basedata$Attitude)

# In our two control groups, mean scores on the dependent variable point toward indifference or slight support for bases in each region: 3.09 in Gyeonggi, 3.06 in Okinawa, 2.8 in Daegu, and 2.46 in Kanagawa. The first three scores are statistically indistinguishable from one another; Kanagawa stands out as more supportive, though the difference is substantively small."

with(basedata[(basedata$TreatA | basedata$TreatB),],tapply(Attitude, Region, mean))
summary(with(basedata[(basedata$TreatA | basedata$TreatB),],lm(Attitude~Region)))

# "We find no significant difference in attitudes toward U.S. military bases between the two control conditions."

h0_att<-with(basedata[(basedata$TreatA | basedata$TreatB),], lm(as.formula(paste0('Attitude ~ TreatB + ', paste(regions, '* TreatB', collapse = ' + ')))))
h0_beh<-with(basedata[(basedata$TreatA | basedata$TreatB),], lm(as.formula(paste0('Behavior ~ TreatB + ', paste(regions, '* TreatB', collapse = ' + ')))))
h0_att_covar<-with(basedata[(basedata$TreatA | basedata$TreatB),], lm(as.formula(paste0('Attitude ~ TreatB + ', paste(covars, '* TreatB', collapse = ' + '), '+', paste(regions, '* TreatB', collapse = ' + ')))))
h0_beh_covar<-with(basedata[(basedata$TreatA | basedata$TreatB),], lm(as.formula(paste0('Behavior ~ TreatB + ', paste(covars, '* TreatB', collapse = ' + '), '+', paste(regions, '* TreatB', collapse = ' + ')))))

summary(h0_att)
summary(h0_beh)
summary(h0_att_covar)
summary(h0_beh_covar)
